﻿using System;

namespace Jasmine.Extensions.Decimals
{
    public static class DecimalExtension
    {
        /// <summary>
        /// Rounds a decimal value to a specified number of fractional digits using midpoint rounding away from zero.
        /// </summary>
        /// <remarks>This method uses <see cref="MidpointRounding.AwayFromZero"/> to ensure that values
        /// exactly halfway between two possible results are rounded away from zero. This behavior matches common
        /// financial rounding practices.</remarks>
        /// <param name="value">The decimal number to be rounded.</param>
        /// <param name="decimals">The number of decimal places in the returned value. Must be between 0 and 28.</param>
        /// <returns>A decimal value rounded to the specified number of decimal places using midpoint rounding away from zero.</returns>
        public static decimal ToFixed(this decimal value, int decimals)=> decimal.Round(value, decimals, MidpointRounding.AwayFromZero);

    }
}
